package com.ht.utils.htmlBean;

import lombok.Data;

import java.util.LinkedList;

@Data
public class TR {
    private Line top;
    private Line bottom;
    private Line left;
    private Line right;
    private LinkedList<TC> tcs = new LinkedList<>();

    public void addTc(TC tc){
        this.tcs.add(tc);
    }
    String toHtml() {
        StringBuilder html = new StringBuilder("<tr style=\"");
        if (this.top != null) {
            html.append("border-top-style:").append(Line.converLineType(this.top.getType()))
                    .append(";border-top-color:").append(Line.converColor(this.top.getColor()))
                    .append(";border-top-width:").append(this.top.getSz() / 250 * 12 / 0.75).append("px;");
        }
        if (this.bottom != null) {
            html.append("border-bottom-style:").append(Line.converLineType(this.bottom.getType()))
                    .append(";border-bottom-color:").append(Line.converColor(this.bottom.getColor()))
                    .append(";border-bottom-width:").append(this.bottom.getSz() / 250 * 12 / 0.75).append("px;");
        }
        if (this.left != null) {
            html.append("border-left-style:").append(Line.converLineType(this.left.getType()))
                    .append(";border-left-color:").append(Line.converColor(this.left.getColor()))
                    .append(";border-left-width:").append(this.left.getSz() / 250 * 12 / 0.75).append("px;");
        }
        if (this.right != null) {
            html.append("border-right-style:").append(Line.converLineType(this.right.getType()))
                    .append(";border-right-color:").append(Line.converColor(this.right.getColor()))
                    .append(";border-right-width:").append(this.right.getSz() / 250 * 12 / 0.75).append("px;");
        }
        html.append("\">");
        if (tcs != null && !tcs.isEmpty()) {
            for (TC tc : tcs) {
                html.append(tc.toHtml());
            }
        }
        html.append("</tr>");
        return html.toString();
    }

}
